package com.fenghongzhang.day009;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class SchoolActivity extends AppCompatActivity {

    private static final String TAG = "SchoolActivity";
    SQLiteDatabase db;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_school);

        SchoolOpenHelp schoolOpenHelp = new SchoolOpenHelp(this, "school.db", null, 1);
        db = schoolOpenHelp.getReadableDatabase();
    }

    public void insert(View view) {
    }

    public void update(View view) {
    }

    public void del(View view) {
    }

    public void query(View view) {
        Cursor cursor = db.query("course", null, null, null, null, null, null);
        if (cursor != null){
            while(cursor.moveToNext()){
                String id = cursor.getString(cursor.getColumnIndex("id"));
                String name = cursor.getString(cursor.getColumnIndex("name"));
                String address = cursor.getString(cursor.getColumnIndex("address"));

                //数据
                Log.i(TAG, "query: "+id+":"+name+":"+address);
            }
        }

    }
}
